<?php
/**
 * User: aka
 * Date: 2018/6/28
 * Time: 14:00
 */

namespace app\reception\controller;


class Mobile extends Front
{
    static private $sowingImg = 'sowing_img';
    static private $foodInfo = 'food_info';
    static private $classificationInfo = 'classification_info';

    private function classificationData(int $pidNum) : array
    {
        $classification = db(self::$classificationInfo)->where(['pid'=>$pidNum,'status'=>1])->select();
        return $classification;
    }

    private function groupFoodTopData(array $where,string $group) : array
    {
        $foodTopdata = db(self::$foodInfo)->where($where)->page($group)->select();
        return $foodTopdata;
    }

    public function mobileIndexView()
    {
        $sowingImgData = db(self::$sowingImg)->where(['status'=>1])->select();
        $computerTop = $this->groupFoodTopData(['top'=>1,'status'=>1],'1,3');
        $printingTop = $this->groupFoodTopData(['top'=>4,'status'=>1],'1,3');
        $hallTop = $this->groupFoodTopData(['top'=>5,'status'=>1],'1,3');
        $officeTop = $this->groupFoodTopData(['top'=>6,'status'=>1],'1,3');
        $assignData = [
            'sowimg'=>$sowingImgData,
            'computer'=>$computerTop,
            'printing'=>$printingTop,
            'hall'=>$hallTop,
            'office'=>$officeTop,
        ];
        return view('mobileIndex',$assignData);
    }

    public function mobileAllFoodView()
    {
        $computer = $this->classificationData(1);
        $printing = $this->classificationData(4);
        $hall = $this->classificationData(5);
        $office = $this->classificationData(6);
        $pageData = $this->getDbOperation()->wherePaginate(self::$foodInfo,['status'=>1],12);
        $assignData = [
            'computer'=>$computer,
            'printing'=>$printing,
            'hall'=>$hall,
            'office'=>$office,
            'pageData'=>$pageData
        ];
        return view('mobileAllFood',$assignData);
    }

    public function mobileTypeFoodView()
    {
        $getParamId = input('param.id');
        $id = base64_decode($getParamId);
        $classificationName = $this->getDbOperation()->find(self::$classificationInfo,['id'=>$id]);
        $computer = $this->classificationData(1);
        $printing = $this->classificationData(4);
        $hall = $this->classificationData(5);
        $office = $this->classificationData(6);
        $pageData = $this->getDbOperation()->wherePaginate(self::$foodInfo,['food_classification'=>$id,'status'=>1],12);
        $assignData = [
            'computer'=>$computer,
            'printing'=>$printing,
            'hall'=>$hall,
            'office'=>$office,
            'pageData'=>$pageData,
            'type'=>$classificationName['classification_name']
        ];
        return view('mobileTypeFood',$assignData);
    }

    public function mobileMsgView()
    {
        $getParamId = input('param.id');
        $id = base64_decode($getParamId);
        $computer = $this->classificationData(1);
        $printing = $this->classificationData(4);
        $hall = $this->classificationData(5);
        $office = $this->classificationData(6);
        $msgInfo = db('enterprise_info')->where(['id'=>1])->find();
        switch ($id)
        {
            case 1:
                $msg = $msgInfo['enterprise_cooperation'];
                $name = '企业合作';
                break;
            case 2:
                $msg = $msgInfo['process_flow'];
                $name = '手续流程';
                break;
            case 3:
                $msg = $msgInfo['matters_needing_attention'];
                $name = '注意事项';
                break;
            case 4:
                $msg = $msgInfo['exemption_from_deposit'];
                $name = '免押金说明';
                break;
            case 5:
                $msg = $msgInfo['enterprise_recovery'];
                $name = '企业回收';
                break;
            case 6:
                $msg = $msgInfo['about_us'];
                $name = '关于我们';
                break;
            default:
                die();
        }
        $assignData = [
            'computer'=>$computer,
            'printing'=>$printing,
            'hall'=>$hall,
            'office'=>$office,
            'msg'=>$msg,
            'name'=>$name
        ];
        return view('mobileMsg',$assignData);
    }
}